package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpDto;
import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpService empService;

//    @PostMapping("/login")
//    public Result login(@RequestBody EmpDto empDto) {
//        LoginInfo loginInfo = empService.login(empDto);
//        if (loginInfo != null) {
//            return Result.success(loginInfo);
//        }
//        return Result.error("用户名或密码错误");
//    }

    @PostMapping("/login")
    public Result login(@RequestBody EmpDto empDto , HttpSession session) {
        LoginInfo loginInfo = empService.login(empDto);

        session.setAttribute("loginUser",loginInfo);

        return Result.success(loginInfo);
    }
}
